/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.gui.security;

import it.polimi.registration.business.security.boundary.EventManager;
import it.polimi.registration.business.security.boundary.NotificationManager;
import it.polimi.registration.business.security.boundary.SystemNotificationManager;
import it.polimi.registration.business.security.boundary.UserManager;
import it.polimi.registration.business.security.boundary.WeatherService;
import it.polimi.registration.business.security.entity.Event;
import it.polimi.registration.business.security.entity.Friend;
import it.polimi.registration.business.security.entity.GroupFriend;
import it.polimi.registration.business.security.entity.User;
import java.io.IOException;
import static java.lang.Boolean.TRUE;
import java.util.Date;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Named;


/**
 *
 * @author Innotommy91
 */

@Named
@Stateless
public class NotificationBean
{

@EJB
private UserManager Um;

@EJB
private EventManager em;

@EJB  
private NotificationManager Nm;

@EJB
private WeatherService ws;

@EJB
private SystemNotificationManager SNM;

private User u1,u2,u3,u4;
private Friend friendnotify;
private GroupFriend gl;
private Event e;
private CalendarBean cb;


    public void createNotification() 
    {
       System.out.print("creo 4 utenti e i relativi gruppi di default");
        u1= new User("tommy","inno","a@e.com.it","sdf");
        Um.save(u1);
        u2=new User("stefano","lucchi","b@e.com.it","sd");
        Um.save(u2);
        u3=new User("marco","rossi","c@e.com.it","sd");
        Um.save(u3);
        u4=new User("paolo","verdi","d@e.com.it","sd");
        Um.save(u4);
    }
    
    public void eliminagruppo()
    {
        
    }
    
    public void crearichiesta()
    {
        Date date = new Date();
        Friend friendnotify = new Friend(u1,u2,date,TRUE,1);
        Nm.save3(friendnotify);
        friendnotify = new Friend(u3,u1,date,TRUE,1);
        Nm.save3(friendnotify);
    }
    
    public void chiamameteo() throws IOException
    {
        ws.weatherService2("Palermo", "7");
        
    }
    
    
    public void sendRequest(User u1)
    { 
       Nm.createFriendRequest(u1);
    }
    
    public void trovata()
    {
        Nm.changeAction(u1, 1);
    }
    
    public void creagruppo()
    {
        gl= new GroupFriend("nuovo gruppo",u1);
        //devo controllare che gli utenti sia gia nel mio gruppo di default senno nn posso aggiungerli
        gl.setBelongers(u2);
        gl.setBelongers(u3);
        Nm.save2(gl);
    }

    public void creaaa()
    {
        em.meteo();
    }
    
    public void accetta(User user)
    {
        Nm.RequestResponse(1,user);
    }
    
    public void rifiuta(User user)
    {
        Nm.RequestResponse(0,user);
    }
    
    public void delete()
    {
        Um.delete(u2);
    }
    
    public void lettaNotificaMeteo(Event evento)
    {
        
        SNM.lettaNotifica(Um.getLoggedUser(), evento);
        
    }
    
    
}